package com.sensePlusVR.utils;

import java.util.ArrayList;
import java.util.List;

import com.sensePlusVR.application.VRApplication;
import com.sensePlusVR.base.BaseActivity;
import com.sensePlusVR.bean.GameItem;
import com.sensePlusVR.setting.bluetooth.BlueScannerActivity;

public class GamePlayStartUtil {
	private static final String TAG = GamePlayStartUtil.class.getSimpleName();
	
	public static void gameStart(BaseActivity context,int gameMode,GameItem gameItem) {
		VRApplication vrApplication = (VRApplication) context.getApplication();
		MySharedPreferences.save(context, "shouldFinish", false);
		MySharedPreferences.save(context, Constant.SP_BLUE_IS_FROM_SETTING, false);

		List<String> glist = new ArrayList<String>();
		
		int realCount = 0;
		int unRealCount = 0;
		
			if(gameItem.getType().equals(Constant.TYPE_DEMO_REAL)||gameItem.getType().equals(Constant.TYPE_REAL)){
				
				realCount++;
				
			}else{
				unRealCount++;
			}
				
			glist.add(GameDownload.getGameConfig(gameItem));
		
		if(realCount!=0&&unRealCount!=0){
			
			return;
		}
		
		boolean isRealGame = realCount>unRealCount;
		
		
		boolean isConnectedVR = vrApplication.isBTConnected();
		if (isConnectedVR) {
			boolean isFromSetting = MySharedPreferences.getBoolean(context,
					Constant.SP_BLUE_IS_FROM_SETTING);
			MyLog.d(TAG, "glist : " + glist.size());
			if (!isFromSetting) {
				GameController.GameStart(context, gameMode, isRealGame,glist,gameItem);
			}
		} else {
			vrApplication.toBTDisconnect();
			GameController.GameSetList(gameMode, isRealGame,glist,gameItem);
			MyPageJump.pageJump(context, BlueScannerActivity.class);
		}
	}

}
